package com.zhuiyun.project.api.addfriend.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.addfriend.entity.AddFriend;
import com.zhuiyun.project.api.addfriend.model.AppFriendModel;
import com.zhuiyun.project.api.addfriend.service.AddFriendService;
import com.zhuiyun.project.common.errorCode.EmErrorCode;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.ObjectUtils;
import com.zhuiyun.project.util.constants.CommonConstants;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName AddFriendController
 * @Description TODO
 * @Author kdj
 * @Date 2023/6/20 14:29
 **/
@RestController
@CrossOrigin
@RequestMapping("/addFriend")
public class AddFriendController {
    @Autowired
    private AddFriendService addFriendService;

    /**
     * @param appFriendModel
     * @Author kdj
     * @Description 新增添加好友的请求数据
     * @Date 2023/6/21 19:29
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @ApiOperation(value = " 新增添加好友的请求数据")
    @PostMapping("/addFriend")
    @OptLog(modular = "添加好友操作", type = CommonConstants.ADD, describe = "新增添加好友的请求数据")
    public CommonResult addFriend(@RequestBody AppFriendModel appFriendModel) {
        return addFriendService.addFriend(appFriendModel);
    }

    /**
     * @param userId
     * @Author kdj
     * @Description 查询我请求过的或者好友请求的数据
     * @Date 2023/6/21 21:07
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @ApiOperation(value = " 查询我请求过的或者好友请求的数据")
    @GetMapping("/getFriendRequestList")
    @OptLog(modular = "添加好友操作", type = CommonConstants.SELECT, describe = "查询我请求过的或者好友请求的数据")
    public CommonResult getFriendRequestList(int userId) {
        return addFriendService.getFriendRequestList(userId);
    }


    /**
     * @param userId
     * @param friendId
     * @Author kdj
     * @Description 根据userID和friencId查询AddFriend信息
     * @Date 2023/6/22 10:41
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @ApiOperation(value = " 根据userID和friencId查询AddFriend信息")
    @GetMapping("/getAddByUserIdAndFriendId")
    @OptLog(modular = "添加好友操作", type = CommonConstants.SELECT, describe = "根据userID和friencId查询AddFriend信息")
    public CommonResult getAddByUserIdAndFriendId(int userId, int friendId) {
        AddFriend andFriendId = addFriendService.getAddByUserIdAndFriendId(userId, friendId);
        if (ObjectUtils.isNotEmpty(andFriendId)) {
            return CommonResult.ok(andFriendId);
        } else {
            return CommonResult.ok(EmErrorCode.ID_NOT_OBJECT);
        }
    }

    /**
     * @param appFriendModel
     * @Author kdj
     * @Description 同意好友添加好友请求
     * @Date 2023/6/23 11:50
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @ApiOperation(value = " 同意好友添加好友请求")
    @PostMapping("/addFriendOK")
    @OptLog(modular = "添加好友操作", type = CommonConstants.UPDATE, describe = "同意好友添加好友请求")
    public CommonResult addFriendOK(@RequestBody AppFriendModel appFriendModel) {
        return addFriendService.addFriendOK(appFriendModel);
    }

    /**
     * @param appFriendModel
     * @Author kdj
     * @Description 拒绝添加好友请求
     * @Date 2023/6/23 11:50
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @ApiOperation(value = " 拒绝添加好友请求")
    @PostMapping("/addFriendNo")
    @OptLog(modular = "添加好友操作", type = CommonConstants.UPDATE, describe = "拒绝添加好友请求")
    public CommonResult addFriendNo(@RequestBody AppFriendModel appFriendModel) {
        return addFriendService.addFriendNo(appFriendModel);
    }

    /**
     * @param userId
     * @param otherUserId
     * @Author kdj
     * @Description 判断之前是否有过好友请求
     * @Date 2023/7/21 11:09
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @ApiOperation(value = " 判断之前是否有过好友请求")
    @GetMapping("/queryAddFriendRecord")
    @OptLog(modular = "查询好友请求", type = CommonConstants.SELECT, describe = "判断之前是否有过好友请求")
    public CommonResult queryAddFriendRecord(int userId, int otherUserId) {
        return addFriendService.queryAddFriendRecord(userId, otherUserId);
    }
}
